
//
//  XFXtittleView.m
//  XFXnews
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "XFXtittleView.h"
#import "XFXtittleModel.h"

@interface XFXtittleView()

@property (nonatomic, strong)NSMutableArray *allarray;
@property (nonatomic, strong)UIView *myView;

@end


@implementation XFXtittleView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
      
    }
    return self;
}

- (void)createSubViews{
    
    for (int i = 0; i < 4; i++) {
        self.myView = [[UIView alloc]initWithFrame:CGRectMake(XFXWIDTH/4*i, 0,XFXWIDTH/4, 150*XFXHEIGHT/736)];
        self.myView .backgroundColor = [UIColor whiteColor];
        
        XFXtittleModel *model = [self.allarray objectAtIndex:i];
        UILabel *mylabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 100*XFXHEIGHT/736,XFXWIDTH/4, 50*XFXHEIGHT/736)];
        UIImageView *myimage = [[UIImageView alloc]initWithFrame:CGRectMake(10*XFXWIDTH/414, 10*XFXHEIGHT/736,XFXWIDTH/5, 90*XFXHEIGHT/736)];
        
        mylabel.textAlignment = NSTextAlignmentCenter;
        
        mylabel.text = model.title;
        [myimage sd_setImageWithURL:[NSURL URLWithString:model.imgsrc]];
      
        self.myView.tag = 100+i;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
        self.myView.userInteractionEnabled = YES;
        
        [self.myView addGestureRecognizer:tap];
        [self.myView  addSubview:myimage];
        [self.myView  addSubview:mylabel];
        [self addSubview:self.myView ];
    }
    
    
    
}

- (void)setArray:(NSMutableArray *)array{
    _array = array;
    self.allarray = _array;
      [self createSubViews];
}

- (void)tapAction:(UITapGestureRecognizer *)tap{
    UIView *view = tap.view;
    NSInteger i = view.tag - 100;
    
    XFXtittleModel *model = [self.array objectAtIndex:i];
    [self.delegate send:model];
    

}


@end
